#!/bin/bash -x

# remove flag-file to remove remainders of old office run written in maintenance step
[ -f ../kill_office ] && rm ../kill_office
if [ -f ../kill_office.log ]
then
    echo Office kiling logfile is as follows
    echo ----------------------------------
    cat ../kill_office.log
    echo ----------------------------------
    rm -f ../kill_office.log
fi


# read config
. ../../steps.config

# for those requiring X
if [ -f LinuxX86Env.Set.sh -o -f LinuxX86-64Env.Set.sh -o -f LinuxIntelEnv.Set.sh -o -f SolarisX86Env.Set.sh -o -f SolarisSparcEnv.Set.sh ]
then
    if [ -z $XvfbBinary ]
    then
      XvfbBinary=/usr/bin/Xvfb
    fi
    echo $XvfbBinary :2
    $XvfbBinary :2 &
    export DISPLAY=:2
    export EXTERNAL_WARNINGS_NOT_ERRORS="TRUE"
    XStarted=Yes
fi

# for solaris X11 deadlock problem
if [ -f SolarisX86Env.Set.sh -o -f SolarisSparcEnv.Set.sh ]
then
    export SAL_NO_XINITTHREADS=TRUE
fi

# put name of OOo config file created by configure in $envname
. ../../getOOoEnv
. $envname

# hack to survive build.pl "feature" :(
export TMP=/tmp

export TEMP="/tmp"
workdir=`pwd`

rcode=0

for test_module in test smoketestdoc
do
    if [ $rcode -eq 0 -a -d $test_module ]
    then
        cd $test_module && perl ../solenv/bin/build.pl && perl ../solenv/bin/deliver.pl
        rcode=$?
        cd $workdir
    fi
done

if [ $rcode -eq 0 ]
then
  cd smoketestoo_native && perl ../solenv/bin/build.pl
  rcode=$?
  cd $workdir
fi

[ "$XStarted" ] && ../../Xvfb_stop.sh

exit $rcode

